package fag.core.game.test.asteroids;

import fag.core.game.StandardDoodad;
import fag.core.geometry.Vector2D;
import fag.core.model.Model;

public class Vaisseau extends StandardDoodad {
	
	private double width = 0.0, height = 0.0, radian = 0.0;
	private Vector2D speed = new Vector2D();

	public Vaisseau(Model model, Vector2D position, Vector2D speed, double angle) {
		super(model);
		width = getBounds().getWidth();
		height = getBounds().getHeight();
		setTranslation(position);
		this.speed = speed;
		addRotation(angle);
	}
	
	public double getWidth() {
		return width;
	}
	
	public double getHeight() {
		return height;
	}
	
	public Vector2D getSpeed() {
		return speed;
	}
	
	public void setSpeed(Vector2D speed) {
		this.speed = speed;
	}
	
	public Vector2D addSpeed(double add_speed) {
		return speed.add(new Vector2D(add_speed * Math.cos(radian), add_speed * Math.sin(radian)));
	}
	
	public void addRotation(double angle) {
		rotate(angle, width / 2.0, height / 2.0, Referential.RELATIVE);
		radian = getRotation() - Math.PI / 2.0;
	}
	
	public void bounce(Vector2D normal) {
		speed.set(speed.add(normal.mul(normal.dot(speed.mul(-1)) * 2)));
	}

	public void step(double dt) {
		translate(speed.x * dt, speed.y * dt, Referential.ABSOLUTE);
	}
}